package com.stoken.service.impl;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.stoken.dao.TravelLeaveMessageDao;
import com.stoken.dao.TravelLeaveReplyDao;
import com.stoken.domain.TravelLeaveMessage;
import com.stoken.domain.TravelLeaveReply;
import com.stoken.service.TravelLeaveReplyService;
import com.symbio.dao.hibernate.GenericDaoImpl;
import com.symbio.service.impl.AbstractServiceImpl;

@Service
public class TravelLeaveReplyServiceImpl extends AbstractServiceImpl<TravelLeaveReply, Long> implements TravelLeaveReplyService{
	
    @Autowired
	private TravelLeaveReplyDao travelLeaveReplyDao;
    
    @Autowired
    private TravelLeaveMessageDao travelLeaveMessageDao;

	@Override
	public GenericDaoImpl<TravelLeaveReply, Long> getDao() {
		return travelLeaveReplyDao;
	}
    
	@Override
	public TravelLeaveReply getMessageReply(String mlmId) {
	    
		return travelLeaveReplyDao.find("leaveTopic.id", mlmId);
	}

	@Override
	public void writeLeaveMessage(String reContext, long leaveId) {
		TravelLeaveReply memberLeaveReply = new TravelLeaveReply();
		memberLeaveReply.setReplyContent(reContext);
		memberLeaveReply.setReplyTime(new Date());
		travelLeaveReplyDao.save(memberLeaveReply);
		TravelLeaveMessage mbLeaveMessage =travelLeaveMessageDao.find(leaveId);		
		mbLeaveMessage.setIsReply(1);
		mbLeaveMessage.setLeaveReply(memberLeaveReply);
		travelLeaveMessageDao.update(mbLeaveMessage);
		
	}


}
